package com.chandra.pos.config.security;

import com.chandra.pos.employee.model.EmployeeModel;
import com.chandra.pos.employee.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * Created by Admin on 3/20/15.
 */
@Component
public class LocalUserDetailService implements UserDetailsService {

    @Autowired
    private EmployeeService employeeService;

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {

        EmployeeModel employee = employeeService.getByUserName(userName);
        if (employee == null) {
            throw new UsernameNotFoundException("User with user name :"
                    + userName + " not found");
        }

        CustomUserBean user = new CustomUserBean(employee);
        return user;
    }


}